<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>04koa-bodyparser</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
  <div class="login-form">
    <span>登录测试</span><br>
    用户名：<input type="text"><br>
    密码： <input type="text">
  </div>
  <button class="reguser">注册</button>
  <button class="login">登录</button>
  <script>
    $(function() {
      $('.reguser').click(function() {
        $.ajax({
          type: 'GET',
          url: 'http://127.0.0.1:3000/api/reguser',
          success: (res) => {
            console.log(res)
          }
        })
      })
      $('.login').click(function() {
        let userInfo = {
          username: $('.login-form input:nth-of-type(1)').val(),
          password: $('.login-form input:nth-of-type(2)').val()
        }
        console.log(userInfo)
        $.ajax({
          type: 'POST',
          url: 'http://127.0.0.1:3000/api/login',
          data: userInfo,
          success: (res) => {
            console.log(res)
          }
        })
      })
    })
  </script>
</body>
</html>